var errors = [
    "System allows only 50 users to be logged in. Please try again later. Sorry for inconvenience",
    "This user is already logged into the system under other browser. Please user another session or log out and try to log in again.",
    "User credentials were entered incorrectly. Page is locked for 10 minutes. Please try again later.",
    "Please enter username",
    "Please enter password",
    "Too short username!",
    "Too short password!",
    "Such user does not exist in the system - please try again",
    "Password is incorrect - please try again"

];
$(function () {
    //Login error
    var req = new XMLHttpRequest();
    req.open('GET', document.location, false);
    req.send(null);
    str = req.getResponseHeader("message");
    if(str!=undefined && str.trim()!="") {
    toastr.error(str);
    }

});
//validation login/password fields
$(document).on("click", ".btn-primary", function(e) {
    e.preventDefault();
    var username_length=$("#username").val().length;
    var password_length=$("#password").val().length;
    if(username_length==0) {
        toastr.error(errors[3]);
    }   else if(username_length<4){
        toastr.error(errors[5]);
    } else if(password_length==0) {
        toastr.error(errors[4]);
    } else if(password_length<6) {
        toastr.error(errors[6]);
    }  else {

        $("#loginform").submit();
        //window.location.href="admin.html";

    }
});